import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name="addminloginServlet",value="/adminloginServlet")
public class adminloginServlet extends HttpServlet {

    @Override
    public void init(ServletConfig config) throws ServletException{
        super.init(config);
        SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,config.getServletContext());
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        response.sendRedirect("admin.html");
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String ID=request.getParameter("ID");
        String rpassword=request.getParameter("rpassword");
        if(ID.equals("admin")&&rpassword.equals("123")){
            response.sendRedirect("admin.html");
            JOptionPane.showMessageDialog(null, "登录成功","【成功了】" , JOptionPane.ERROR_MESSAGE);

            return;
        }else if(ID==null||ID.equals("")||rpassword==null||rpassword.equals("")){
            JOptionPane.showMessageDialog(null, "账号或密码有误,请再次检验","【出错啦】" , JOptionPane.ERROR_MESSAGE);
            response.sendRedirect("login.html");
            return;
        }

    }
}